package com.zhkj.txg.module.product.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhkj.txg.R
import com.zhkj.txg.module.product.entity.ProblemEntity

class ProblemAdapter : BaseQuickAdapter<ProblemEntity, BaseViewHolder>(R.layout.item_product_problem) {

    init {
        setOnItemClickListener { _, _, position ->
            selectedPosition = if (selectedPosition != position) position else -1
            notifyDataSetChanged()
        }
    }

    private var selectedPosition: Int = -1

    override fun convert(helper: BaseViewHolder, item: ProblemEntity) {
        helper.setText(R.id.tvProblem, item.title).setText(R.id.tvAnswer, item.content)
            .setGone(R.id.tvAnswer, selectedPosition != helper.adapterPosition)
        helper.itemView.isSelected = selectedPosition == helper.adapterPosition
    }
}